var express = require('express');
var router = express.Router();
var path = require("path");
var fs = require("fs");

/* GET home page. */
router.get('/', function (req, res, next) {
    var imgs = ''
    var dirs = [];
    var pathName = "./public/images/";
    res.setHeader("Content-Type", "text/html;charset=utf-8")
    fs.readdir(pathName, function (err, files) {

        for (var i = 0; i < files.length; i++) {
           
            var img = `<div><img data-src="/imgs/${files[i]}" /></div>`
          
            imgs +=img
            fs.writeFile('E:\\ht.txt', imgs, function (error) {
                if (error) {
                  console.log('写入失败')
                } else {
                  console.log('写入成功了')
                }
              })
           //console.log(imgs)
            fs.stat(path.join(pathName, files[i]), function (err, data) {
                if (data.isFile()) {
                    dirs.push(files[i]); 
                }
            });
        } 
    })
    res.end()
   
    
  
   
    

});



module.exports = router;
